package com.ftf.tp.blog.domain.configuration.service;

import com.ftf.tp.blog.domain.article.aggregate.ArticleAgg;
import com.ftf.tp.blog.domain.article.event.ColumnArticleUpdateEvent;
import com.ftf.tp.blog.domain.configuration.repository.ColumnRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author tanghao
 * @date 2022/8/8
 */
@Service
public class ColumnService {

    @Resource
    private ColumnRepository columnRepository;


    /**
     * 文章专栏关系同步
     *
     * @param articleAgg 文章聚合
     */
    public void articleSync(ArticleAgg articleAgg) {
        columnRepository.articleSync(articleAgg);
    }


    public void articleNumUpdate(ColumnArticleUpdateEvent columnArticleUpdateEvent) {
        if (columnArticleUpdateEvent.getType() == 1) {
            columnArticleUpdateEvent.setNums(-columnArticleUpdateEvent.getNums());
        }
        columnRepository.articleNumUpdate(columnArticleUpdateEvent.getColumnIdList(),columnArticleUpdateEvent.getNums());
    }
}
